package com.hll.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hll.api.entity.ShopCar;
import com.hll.api.entity.User;
import com.hll.api.mapper.ShopCarMapper;
import com.hll.api.service.IShopCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 购物车 服务实现类
 * </p>
 *
 * @author 何龙
 * @since 2019-06-29
 */
@Service
public class ShopCarServiceImpl extends ServiceImpl<ShopCarMapper, ShopCar> implements IShopCarService {

	@Autowired
	ShopCarMapper mapper;

	@Override
	public ShopCar getShopCar(String goodsId, Integer userId) {
		QueryWrapper<ShopCar> wrapper=new QueryWrapper<>();
		wrapper.eq("user_id",userId).eq("goods_id",goodsId);
		return mapper.selectOne(wrapper);
	}

	@Override
	public List<ShopCar> getShopCarList(User user) {
		QueryWrapper<ShopCar> wrapper=new QueryWrapper<>();
		wrapper.eq("user_id",user.getId());
		wrapper.orderByDesc("date");
		return mapper.selectList(wrapper);
	}
}
